<?php
/* This file is part of Mirasol CMS
   Copyright (C) 2011 by Chris Alban Hansen.
   Released under the terms of the GNU General Public License.
   See COPYING in the top level directory of the Mirasol CMS installation. */

if (!defined ("_LARGETEXT_PHP_"))
{
  define ("_LARGETEXT_PHP_", "1");
  
  function largetext_format ($s)
  {
    /* Bold text */
    $s = preg_replace ("/\*(.+?)\*/", '<strong>\1</strong>', $s);
    
    /* Pre-formatted text */
    $s = preg_replace ("/{{{(.+?)}}}/", '<pre>\1</pre>', $s);
    
    /* Links */
    $s = preg_replace ("/\[(.*?)\s(.*?)\]/", '<a href="\1">\2</a>', $s);
    $s = preg_replace ("/\[(.*?)\]/", '<a href="\1">\1</a>', $s);
      
    return $s;
  }

  function largetext_unformat ($s)
  {
    /* Bold text */
    $s = str_replace ("<strong>", '*', $s);
    $s = str_replace ("</strong>", '*', $s);

    /* Pre-formatted text */
    $s = str_replace ("<pre>", '{{{', $s);
    $s = str_replace ("</pre>", '}}}', $s);

    /* Links */
    $s = preg_replace ("/<a href=\"(.*?)\">(.*?)<\/a>/", '[\1 \2]', $s);
    
    return $s;
  }
}
?>
